package two.chapter_4.c4_1;

import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

public class DegreesOfSeparation {

    public static void main(String[] args){
        String graphPath="/Users/wind/downloads/高焕堂EIT/Algorithms-master/data/routes.txt";
        String delim=" ";
        SymbolGraph sg=new SymbolGraph(graphPath,delim);
        Graph g=sg.g();
        String source="JFK";
        if(!sg.contains(source)){
            StdOut.println(source+"not in database.");
            return;
        }
        int s=sg.index(source);
        BreadthFirstPaths bfs=new BreadthFirstPaths(g,s);
        while (!StdIn.isEmpty()){
            String sink=StdIn.readLine();
            if (sg.contains(sink)){
                int t=sg.index(sink);
                if (bfs.hasPathTo(t)){
                    for (int v:bfs.pathTo(t)){
                        StdOut.println("    "+sg.name(v));
                    }
                }else {
                    StdOut.println("Not connected");
                }
            }else {
                StdOut.println("Not in database");
            }
        }
    }
}
